<template>
  <div style="background-color: #fff; height: 100vh">
    <el-form
      style="width: 1411px; height: 88px; background-color: #fff; padding: 25px 56px 25px 17px"
    >
      <el-row :gutter="24" style="position: relative">
        <el-col :span="6"
          ><p style="font-size: 12px">菜单名称</p>
          <el-input v-model="form.menuName" placeholder="请输入" style="width: 325px; height: 40px"
        /></el-col>
        <el-col :span="6">
          <p style="font-size: 12px">状态</p>
          <el-select
            v-model="form.status"
            class="m-2"
            placeholder="请选择状态"
            size="large"
            style="width: 325px"
          >
            <el-option label="正常" value="1"></el-option>
            <el-option label="停用" value="0"></el-option>
          </el-select>
        </el-col>
        <el-col :span="6" style="position: absolute; right: 20px; top: 30%">
          <el-button
            style="
              width: 92px;
              height: 40px;
              border-radius: 20px;
              background-color: #05cc95;
              color: #fff;
            "
            @click="souso"
            >搜索</el-button
          >
          <el-button
            style="width: 92px; height: 40px; border-radius: 20px; background-color: #eaeaea"
            @click="czbtn"
            >重置</el-button
          >
        </el-col>
      </el-row>
    </el-form>
    <el-form>
      <div style="height: 83px; background-color: #f9f9f9; position: relative">
        <el-button
          @click="dialogVisible = true"
          style="
            position: absolute;
            width: 92px;
            height: 40px;
            border-radius: 20px;
            background-color: #ec3a2c;
            color: #fff;
            right: 57px;
            top: 25%;
          "
          >新增</el-button
        >
      </div>
    </el-form>
    <el-form>
      <el-table  :data="list" :border="parentBorder" style="width: 100%">
        <el-table-column label="菜单名称" width="180" prop="menuName">
        </el-table-column>
        <el-table-column label="图标" prop="icon" width="130" sortable />
        <el-table-column label="排序" type="index" width="130" sortable />
        <el-table-column label="权限标识" prop="perms" width="260" sortable />
        <el-table-column label="组件路径" prop="component" width="260" sortable />
        <el-table-column label="状态" prop="status" width="130" sortable >
          <template v-slot="{ row }">
            <span v-if="row.status === 0">正常</span>
            <span v-else>停用</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="createTime" width="208" sortable />
        <el-table-column label="操作" prop="name" width="156" sortable >
          <template v-slot="{ row }">
            <el-button
              type="text"
              size="small"
              style="width: 26px; height: 17px"
              @click="bj(row.id)"
              >修改</el-button
            >
            <el-button
              type="text"
              size="small"
              style="width: 26px; height: 17px; color: #ec3a2c"
              @click="dialogVisible = true"
              >新增</el-button
            >
            <el-button
              type="text"
              size="small"
              style="width: 26px; height: 17px"
              @click="reset(row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="demo-pagination-block" style="margin-top: 20px; margin-left: 30%">
        <el-pagination
          v-model:current-page="form.pageNum"
          v-model:page-size="form.pageSize"
          :page-sizes="[10, 20, 30, 40]"
          :small="small"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-form>

    <!-- 添加菜单弹框 -->
    <el-dialog v-model="dialogVisible" title="添加菜单" width="618" :before-close="handleClose">
      <!-- <el-divider /> -->
      <el-form style="margin-left: 20px">
        <el-row :gutter="24" style="margin-left: 5px">
          <el-col :span="24">
            <el-form-item>
              <p>上级菜单</p>
              <el-tree-select
                v-model="value"
                :data="data"
                :render-after-expand="false"
                style="width: 426px; height: 40px; margin-left: 12px"
                size="large"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 5px; margin-top: -15px">
          <el-col :span="24">
            <el-form-item>
              <p>菜单类型</p>
              <div>
                <el-radio-group v-model="radio1" class="ml-4" style="margin-left: 12px">
                  <el-radio label="1" size="large">目录</el-radio>
                  <el-radio label="2" size="large">菜单</el-radio>
                  <el-radio label="2" size="large">按钮</el-radio>
                </el-radio-group>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 5px; margin-top: -15px">
          <el-col :span="24">
            <el-form-item>
              <p>菜单图标</p>
              <el-input
                style="width: 426px; height: 40px; margin-left: 12px"
                placeholder="请输入用户名称"
                prefix-icon="search"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 5px; margin-top: -15px">
          <el-col :span="12">
            <el-form-item>
              <p>菜单名称</p>
              <el-input
                style="width: 180px; height: 40px; margin-left: 12px"
                placeholder="请输入菜单名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <p>显示排序</p>
              <el-input-number
                style="margin-left: 12px"
                v-model="num"
                :min="1"
                :max="10"
                controls-position="right"
                size="large"
                @change="handleChange"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 5px; margin-top: -15px">
          <el-col :span="12">
            <el-form-item>
              <p>是否外链</p>
              <div>
                <el-radio-group v-model="radio1" class="ml-4" style="margin-left: 12px">
                  <el-radio label="1" size="large">是</el-radio>
                  <el-radio label="2" size="large">否</el-radio>
                </el-radio-group>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <p>路由地址</p>
              <el-input
                style="width: 180px; height: 40px; margin-left: 12px"
                placeholder="请输入路由地址"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 5px; margin-top: -15px">
          <el-col :span="12">
            <el-form-item>
              <p>显示状态</p>
              <div>
                <el-radio-group v-model="radio1" class="ml-4" style="margin-left: 12px">
                  <el-radio label="1" size="large">显示</el-radio>
                  <el-radio label="2" size="large">隐藏</el-radio>
                </el-radio-group>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <p>菜单状态</p>
              <div>
                <el-radio-group v-model="radio1" class="ml-4" style="margin-left: 12px">
                  <el-radio label="1" size="large">正常</el-radio>
                  <el-radio label="2" size="large">停用</el-radio>
                </el-radio-group>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="dialogVisible = false">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { getuserlist } from '@/api/user.js'
import { ref, onMounted } from 'vue'
const dialogVisible = ref(false)
const list = ref([])
const form = ref({
  pageNum: 1,
  pageSize: 10
})
const total = ref(null)
const getuserlistAPI = async () => {
  const { data } = await getuserlist(form.value)
  console.log(data)
  list.value = data.records
  total.value = data.total
  // 时间
  list.value.forEach((item) => {
    const date = new Date(item.createTime)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    item.createTime = `${year}-${'0' + month}-${day}`
    const date1 = new Date(item.endTime)
    const year1 = date1.getFullYear()
    const month1 = date1.getMonth() + 1
    const day1 = date1.getDate()
    item.endTime = `${year1}-${'0' + month1}-${day1}`
  })
}
// 搜素功能
const souso = () => {
  getuserlistAPI()
}
// 重置按钮
const czbtn = () => {
  form.value = {
    pageNum: 1,
    pageSize: 10
  }
  getuserlistAPI()
}
// 分页
const handleCurrentChange = (newpage) => {
  form.value.pageNum = newpage
  getuserlistAPI(form.value)
}
onMounted(() => {
  getuserlistAPI()
})
</script>

<style lang="scss" scoped>
:deep(.el-input__wrapper) {
  border-radius: 7px;
  background-color: #f9f9f9;
}
.el-main {
  --el-main-padding: 0;
}
</style>
